package com.zzgele.qmzb.api.web;

import com.alibaba.boot.dubbo.annotation.DubboConsumer;
import com.zzgele.qmzb.api.core.Constants;
import com.zzgele.qmzb.api.core.Result;
import com.zzgele.qmzb.api.core.ResultGenerator;
import com.zzgele.qmzb.api.model.User;
import com.zzgele.qmzb.api.service.FansService;
import com.zzgele.qmzb.api.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 通知提醒
 */

@RestController
@RequestMapping("/notic")
public class NoticController {
    private final Logger logger = LoggerFactory.getLogger(NoticController.class);
    @DubboConsumer
    private UserService userService;
    @DubboConsumer
    private FansService fansService;

    /**
     * 私信通知状态：0代表打开，1代表关闭
     * @param login_uid
     * @return
     */
    @PostMapping("/private")
    public Result remind(Long login_uid, Integer status) {
        User user = userService.findById(login_uid);
        if (user == null) {
            return ResultGenerator.genFailResult("用户不存在");
        }
        HashMap map;
        map = new HashMap();
        if (status== Constants.PRIVATE_STATUS){
            map.put("status", Constants.PRIVATE_STATUS);
        }else{
            map.put("status",1);
        }
        map.put("uid", user.getId());
        userService.UpdatePrivate(map);
        HashMap hashMap = new HashMap();
        hashMap.put("private_notice_status", map.get("status"));
        return ResultGenerator.genSuccessResult(hashMap);
    }

    /**
     * 开播提醒状态：0代表打开，1代表关闭
     * @param login_uid
     * @return
     */
    @PostMapping("/broadcast")
    public Result broadcast(Long login_uid, Integer status) {
        User user = userService.findById(login_uid);
        if (user == null) {
            return ResultGenerator.genFailResult("用户不存在");
        }
        HashMap map;
        map = new HashMap();
        if (status== Constants.Broadcast_STATUS){
            map.put("status", Constants.Broadcast_STATUS);
        }else{
            map.put("status",1);
        }
        map.put("uid", user.getId());
        userService.UpdateBroadcast(map);
        HashMap hashMap = new HashMap();
        hashMap.put("broadcast_status",map.get("status"));

        map = new HashMap();
        map.put("fans_uid", login_uid);
        List<HashMap> followList = fansService.getList(map);
        hashMap.put("followList",followList);
        return ResultGenerator.genSuccessResult(hashMap);
    }
}
